﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LiveCPEWinForm.Gestionnaire;

namespace LiveCPEWinForm.comp
{
    public partial class CsWall : UserControl
    {
        private GestAPP lGestAPP;
        public CsWall(GestAPP pGestAPP)
        {
            InitializeComponent();
            // Récupération Gestionnaire
            lGestAPP = pGestAPP;
            // Chargement des messages
            LoadMessages();
        }
        
        public void LoadMessages()
        {
            // Nouvelle liste de message
            List<GestMessage> lstMessage = lGestAPP.GestMessages;
            // Si pas de message
            if (lstMessage.Count == 0)
                lblStatus.Text = "You have no message recorded !";
            else
            {
                lblStatus.Text = "You have "+Convert.ToString(lstMessage.Count())+" message recorded !";
                int lCurTop = 120;
                foreach (GestMessage msg in lstMessage)
                {
                    // Creation d'un Cs métier
                    CsMessage cs = new CsMessage(lGestAPP,msg);
                    cs.Parent = this;
                    cs.Top = lCurTop;
                    cs.Left = 17;
                    cs.Refresh();
                    // Nouvelle hauteur pour le prochain message
                    lCurTop += cs.Height + 50;
                }
            }
        }
        // Envois d'un message
        private void btnPubli_Click(object sender, EventArgs e)
        {
            // S'il y a du texte
            if (tbMessage.Text.Length > 0)
            {
                lGestAPP.SendPublicMessage(lGestAPP.UserName, tbMessage.Text);
                (sender as Button).Visible = false;
            }
        }
    }
}
